package top.lixunda.ecommerce.server.good.api.entity.db;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableId;

import com.baomidou.mybatisplus.annotation.TableField;

import java.io.Serializable;
import java.util.Map;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 支付宝支付通知回调数据
 * </p>
 *
 * @author Xumda
 * @since 2020-03-02
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("alipay_notify")
@ApiModel(value = "AlipayNotifyDO对象", description = "支付宝支付通知回调数据")
public class AlipayNotifyDO extends Model<AlipayNotifyDO> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "用户id")
    @TableField("user_id")
    private Integer userId;

    @ApiModelProperty(value = "订单id")
    @TableField("order_id")
    private Integer orderId;

    @ApiModelProperty(value = "时间")
    @TableField("gmt_create")
    private String gmtCreate;

    @TableField("subject")
    private String subject;

    @TableField("buyer_id")
    private String buyerId;

    @TableField("body")
    private String body;

    @TableField("invoice_amount")
    private String invoiceAmount;

    @TableField("notify_id")
    private String notifyId;

    @TableField("fund_bill_list")
    private String fundBillList;

    @TableField("notify_type")
    private String notifyType;

    @TableField("trade_status")
    private String tradeStatus;

    @TableField("receipt_amount")
    private String receiptAmount;

    @TableField("app_id")
    private String appId;

    @TableField("buyer_pay_amount")
    private String buyerPayAmount;

    @TableField("seller_id")
    private String sellerId;

    @TableField("gmt_payment")
    private String gmtPayment;

    @TableField("notify_time")
    private String notifyTime;

    @TableField("passback_params")
    private String passbackParams;

    @TableField("version")
    private String version;

    @TableField("out_trade_no")
    private String outTradeNo;

    @TableField("total_amount")
    private String totalAmount;

    @TableField("trade_no")
    private String tradeNo;

    @TableField("auth_app_id")
    private String authAppId;

    @TableField("point_amount")
    private String pointAmount;


    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    /**
     * 生成AlipayNotifyDO对象用于插入操作
     *
     * @param map     订单付款通知回调信息
     * @param userId  用户Id
     * @param orderId 订单Id
     * @return AlipayNotifyDO
     */
    public static AlipayNotifyDO fromMap(Map<String, String> map, Integer userId, Integer orderId) {
        AlipayNotifyDO alipayNotifyDO = new AlipayNotifyDO();
        alipayNotifyDO.setUserId(userId)
                .setOrderId(orderId)
                .setGmtCreate(map.get("gmt_create"))
                .setSubject(map.get("subject"))
                .setBuyerId(map.get("buyer_id"))
                .setBody(map.get("body"))
                .setInvoiceAmount(map.get("invoice_amount"))
                .setNotifyId(map.get("notify_id"))
                .setFundBillList(map.get("fund_bill_list"))
                .setNotifyType(map.get("notify_type"))
                .setTradeStatus(map.get("trade_status"))
                .setReceiptAmount(map.get("receipt_amount"))
                .setAppId(map.get("app_id"))
                .setBuyerPayAmount(map.get("buyer_pay_amount"))
                .setSellerId(map.get("seller_id"))
                .setGmtPayment(map.get("gmt_payment"))
                .setNotifyTime(map.get("notify_time"))
                .setPassbackParams(map.get("passback_params"))
                .setVersion(map.get("version"))
                .setOutTradeNo(map.get("out_trade_no"))
                .setTotalAmount(map.get("total_amount"))
                .setTradeNo(map.get("trade_no"))
                .setAuthAppId(map.get("auth_app_id"))
                .setPointAmount(map.get("point_amount"));
        return alipayNotifyDO;
    }

}
